package com.tmc.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

import com.tmc.bean.common.ContextInfo;
import com.tmc.bean.common.Pagination;
import com.tmc.constant.FareConstant.PolicyStatus;
import com.tmc.entity.intair.TripartitePolicy;
import com.tmc.util.ObjectUtil;

@Repository
public class TripartitePolicyDaoImpl extends BaseDaoImpl<TripartitePolicy>{
	public Pagination<TripartitePolicy> findByCon(ContextInfo context, TripartitePolicy cond, Integer pageIndex, Integer pageSize){
		Map<String,Object> params =new HashMap<String,Object>();
		StringBuilder sql = new StringBuilder();
		sql.append(" from TripartitePolicy c where c.enabledFlag = 'Y'");
		if(ObjectUtil.hasText(cond.getProtocolNo())){
			sql.append(" and c.protocolNo= :protocolNo");
			params.put("protocolNo", cond.getProtocolNo());
		}
		if(cond.getClientId() != null){
			sql.append(" and c.clientId= :clientId");
			params.put("clientId", cond.getClientId());
		}
		if(ObjectUtil.hasText(cond.getAirline())){
			sql.append(" and c.airline= :airline");
			params.put("airline", cond.getAirline());
		}
		if(ObjectUtil.hasText(cond.getStatus())){
			sql.append(" and c.status= :status");
			params.put("status", cond.getStatus());
		}
		sql.append(" order by c.lastUpdateDate desc ");
		return this.findPagination(sql.toString(), params, pageIndex, pageSize);		
	}

	public List<TripartitePolicy> findListByPolicy(ContextInfo context, TripartitePolicy cond) {
		Map<String,Object> params = new HashMap<String,Object>();
		StringBuilder sql = new StringBuilder();
		sql.append(" FROM TripartitePolicy c WHERE c.enabledFlag = 'Y'");
		
		sql.append(" and c.status = :status");
		params.put("status", PolicyStatus.UP.getStatus());
		
		if(ObjectUtil.hasText(cond.getFlightType())){
			sql.append(" and c.flightType like :flightType");
			params.put("flightType", "%"+cond.getFlightType()+"%");
		}
		if(ObjectUtil.hasText(cond.getOfficeNo())){
			sql.append(" and c.officeNo = :officeNo");
			params.put("officeNo", cond.getOfficeNo());
		}
		if(ObjectUtil.hasText(cond.getAutoTicketingFlag())){
			sql.append(" and c.autoTicketingFlag = :autoTicketingFlag");
			params.put("autoTicketingFlag", cond.getAutoTicketingFlag());
		}
		return this.findList(sql.toString(), params);
	}
	

}
